#!/bin/bash

#
# Human readable logfmt timestamps (ts)
#
# Usage:
#
# kubectl logs deploy/iox-router-1000 -c iox -f | ./scripts/logfmts
#
# Timestamps are printed in UTC
#

set -eu -o pipefail

if ! command -v gawk &> /dev/null; then
  echo "GNU awk required"
  echo "  brew install gawk"
  echo "  apt-get install gawk"
  echo "  ...."
fi

# portable way of saying TZ=UTC
export TZ=C

# shellcheck disable=SC2016
exec gawk -F"time=" '{print strftime("%Y-%m-%d %H:%M:%S", $2/1000000000), $1 }'
